#ifndef LIBTORRENT_PEER_CONNECTION_SUB_H
#define LIBTORRENT_PEER_CONNECTION_SUB_H

#include "rate.h"
#include "piece.h"
#include "peer_connection_common.h"

namespace torrent {

class Sub {

public:
	friend class PeerConnection;
	typedef std::list<Piece> PieceList;

	Sub() :
		choked(true),
		interested(true),
		state(IDLE),
		lastCommand(NONE),
		buf(NULL),
		pos(0),
		length(0),
		lengthOrig(0)
		{}

	bool c_choked() const { return choked; }
	bool c_interested() const { return interested; }

	Rate& c_rate() { return rate; }

	PieceList& c_list() { return list; }

protected:
	bool choked;
	bool interested;

	State state;
	Protocol lastCommand;

	char* buf;
	unsigned int pos;
	unsigned int length;
	unsigned int lengthOrig;

	PieceList list;

	Rate rate;
};

}  // namespace torrent
#endif // LIBTORRENT_PEER_CONNECTION_SUB_H
